package com.xiewz.controller;

import com.xiewz.pojo.Comment;
import com.xiewz.service.ApiCommentService;
import com.xiewz.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api")
public class ApiCommentController {
    @Autowired
    private ApiCommentService commentService;

    // http://localhost:8080/api/findCommentById?id=1
    @RequestMapping(value = "/findCommentById")
    public Comment findCommentById(Integer id) {

        Comment comment = commentService.findCommentById(id);
        return comment;
    }

    @RequestMapping(value = "/updateComment")
    public Comment updateComment(Comment comment) {
        Comment commentById = commentService.findCommentById(comment.getId());
        commentById.setAuthor(comment.getAuthor());
        Comment res = commentService.updateComment(commentById);
        return res;
    }

    @RequestMapping(value = "/deleteComment")
    public void deleteComment(Integer id) {
        commentService.deleteComment(id);
    }

}
